package com.durian.affairs.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.durian.affairs.api.vo.UpdatePaymentForm;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.durian.common.log.annotation.Log;
import com.durian.common.log.enums.BusinessType;
import com.durian.common.security.annotation.RequiresPermissions;
import com.durian.affairs.api.domain.CwPaymentPlan;
import com.durian.affairs.service.ICwPaymentPlanService;
import com.durian.common.core.web.controller.BaseController;
import com.durian.common.core.web.domain.AjaxResult;
import com.durian.common.core.utils.poi.ExcelUtil;
import com.durian.common.core.web.page.TableDataInfo;

/**
 * 付款计划管理Controller
 * 
 * @author durian
 * @date 2022-06-26
 */
@RestController
@RequestMapping("/cwPaymentPlan")
public class CwPaymentPlanController extends BaseController
{
    @Autowired
    private ICwPaymentPlanService cwPaymentPlanService;

    /**
     * 查询付款计划管理列表
     */
    @RequiresPermissions("affairs:cwPaymentPlan:list")
    @GetMapping("/list")
    public TableDataInfo list(CwPaymentPlan cwPaymentPlan)
    {
        startPage();
        List<CwPaymentPlan> list = cwPaymentPlanService.selectCwPaymentPlanList(cwPaymentPlan);
        return getDataTable(list);
    }

    /**
     * 修改支付信息
     */
    @PutMapping("/payForTheOrder")
    public AjaxResult payForTheOrder(@RequestBody UpdatePaymentForm updatePaymentForm)
    {
        return toAjax(cwPaymentPlanService.payForTheOrder(updatePaymentForm));
    }

    /**
     * 导出付款计划管理列表
     */
    @RequiresPermissions("affairs:cwPaymentPlan:export")
    @Log(title = "付款计划管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, CwPaymentPlan cwPaymentPlan)
    {
        List<CwPaymentPlan> list = cwPaymentPlanService.selectCwPaymentPlanList(cwPaymentPlan);
        ExcelUtil<CwPaymentPlan> util = new ExcelUtil<CwPaymentPlan>(CwPaymentPlan.class);
        util.exportExcel(response, list, "付款计划管理数据");
    }

    /**
     * 获取付款计划管理详细信息
     */
    @RequiresPermissions("affairs:cwPaymentPlan:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(cwPaymentPlanService.selectCwPaymentPlanById(id));
    }

    /**
     * 新增付款计划管理
     */
    @RequiresPermissions("affairs:cwPaymentPlan:add")
    @Log(title = "付款计划管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CwPaymentPlan cwPaymentPlan)
    {
        return toAjax(cwPaymentPlanService.insertCwPaymentPlan(cwPaymentPlan));
    }

    /**
     * 修改付款计划管理
     */
    @RequiresPermissions("affairs:cwPaymentPlan:edit")
    @Log(title = "付款计划管理", businessType = BusinessType.UPDATE)
    @PutMapping("/update")
    public AjaxResult edit(@RequestBody CwPaymentPlan cwPaymentPlan)
    {
        return toAjax(cwPaymentPlanService.updateCwPaymentPlan(cwPaymentPlan));
    }

    /**
     * 删除付款计划管理
     */
    @RequiresPermissions("affairs:cwPaymentPlan:remove")
    @Log(title = "付款计划管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(cwPaymentPlanService.deleteCwPaymentPlanByIds(ids));
    }

//    @RequestMapping("/aaa")
//    public UpdatePaymentForm aaa(@RequestBody UpdatePaymentForm updatePaymentForm){
//        System.out.println(updatePaymentForm);
//        return updatePaymentForm;
//    }


}
